package com.anxin.act.task.complete.impl;


import com.anxin.act.task.complete.TaskComplete;
import com.anxin.act.task.service.JumpTaskService;
import com.anxin.act.task.vo.TaskVo;
import com.anxin.act.utils.ActTaskUtils;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * 正常提交待办
 *
 * @author: liuxiangyu
 * @date: 2020/4/26 16:28
 */
@Service
public class RejectedJumpImpl extends TaskComplete {

    @Autowired
    private JumpTaskService jumpTaskService;

    /**
     * 提交流程
     *
     * @param taskVo
     */
    public String complete(TaskVo taskVo) {
        // String rejectedCompleteType = taskVo.getTask().getTaskLocalVariables().get("rejectedCompleteType").toString();

        String rejectedCompleteNode = taskVo.getTask().getTaskLocalVariables().get("rejectedCompleteNode").toString();


        // 保存审批意见
        super.addComment(taskVo);


        List<Task> taskList = ActTaskUtils.getTaskList(taskVo.getTaskKey(), taskVo.getActId());

        if (taskList.size() == 1){
            jumpTaskService.jumpTask(taskVo.getActId(), taskVo.getTaskId(), rejectedCompleteNode, new HashMap<String, Object>());
        }else {
            super.completeTask(taskVo);
        }


        // 签收任务
        ActTaskUtils.claimTask(taskVo.getActId());

        return taskVo.getId();

    }


}
